// 232. 用栈实现队列

class MyQueue {
  // constructor() {

  // }

  // 输入栈
  protected input: number[] = [];
  // 输出栈
  protected output: number[] = [];

  push(x: number): void {
    this.input.push(x);
  }

  pop(): number {
    !this.output.length && this.change();
    return this.output.pop();
  }

  peek(): number {
    !this.output.length && this.change();
    return this.output[this.output.length - 1];
  }

  empty(): boolean {
    return !this.output.length && !this.input.length;
  }

  private change(): void {
    while (this.input.length) {
      this.output.push(this.input.pop());
    }
  }
}

/**
 * Your MyQueue object will be instantiated and called as such:
 * var obj = new MyQueue()
 * obj.push(x)
 * var param_2 = obj.pop()
 * var param_3 = obj.peek()
 * var param_4 = obj.empty()
 */
